function returnConfig(){
	window.location.href = "emailconfig.jsp";
}

$(function(){
	$("#btnclear").live("click",function(){
		clear();
	});
});

function clear(){
	$("#txtSmtp").val('');
	$("#txtemail").val('');
	$("#txtPort").val('');
	$("#txtPass").val('');
	$("#txttitle").val('');
	$("#txtcontent").val('');
}

function addConfig(){
	var smtp = $("#txtSmtp").val();
	if(smtp == ""){
		layer.alert('邮件服务器地址不能为空', 2);
		return;
	}
	
	var email = $("#txtemail").val();
	if(email == ""){
		layer.alert('发送邮箱不能为空', 2);
		return;
	}
	
	
	if(email.indexOf("@") < 0 || email.indexOf(".") < 0){
		layer.alert('发送邮箱格式不正确', 2);
		return;
	}
	
	var port = $("#txtPort").val();
	if(port == ""){
		layer.alert('邮件端口不能为空', 2);
		return;
	}
	
	var pass = $("#txtPass").val();
	if(pass == ""){
		layer.alert('发送邮箱密码不能为空', 2);
		return;
	}
	
	var title = $("#txttitle").val();
	if(title == ""){
		layer.alert('邮件标题不能为空', 2);
		return;
	}
	var obj = new Object();
	obj.mailServerHost = smtp;
	obj.email = email;
	obj.mailServerPort = port;
	obj.emailTitle = title;
	obj.emailContent = "";
	obj.userPassword = pass;
	var json = JSON.stringify(obj);
	$.ajax({
    	type : 'post',
		dataType: 'json',
		data: json,
		contentType: "application/json",
		async: false, 
        url: '/meileche/admin/con.do?action=0',     
        success: function(data) {
			if(data == "1"){
				clear();
				layer.alert('添加成功', 2);
			}else{
				layer.alert('添加失败', 2);
			}
        }  
    }); 
}